<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title site-demo-title">
        <li class="layui-this rule-title"></li>
    </ul>
    <div class="main-content">
      <div class="layui-form-item">
	    <label class="layui-form-label ip-type"></label>
	    <div class="layui-input-inline">
            <select name="type" readonly="readonly" class="layui-input">
                <option value="ipWhitelist">ip白名单</option>
                <option value="ipBlocklist">ip黑名单</option>
            </select>
	    </div>
	  </div>
	  <div class="layui-form-item">
        <label class="layui-form-label ip-value"></label>
        <div class="layui-input-inline">
          <input type="text" name="value" autocomplete="off" placeholder="" class="layui-input">
        </div>

      </div>
       <div class="layui-form-item">
	    <div class="layui-input-block">
	      <button class="layui-btn save"></button>
	      <button class="layui-btn layui-btn-primary back"></button>
	    </div>
	  </div>
    </div>
</div>
<script>
if(window.ipIndex){
    $(".rule-title").html($.i18n.prop('rule.edit'));
    $(".back").html($.i18n.prop('public.back'));
    $("[name='type']").val(ipList[ipIndex].type);
    $("input[name='value']").val(ipList[ipIndex].value);
}else {
    $(".rule-title").html($.i18n.prop('rule.add'));
    $(".back").hide();
}
$(".ip-value").html($.i18n.prop('ip.value'));
$(".ip-type").html($.i18n.prop('ip.type'));
$("input[name='value']").attr("placeholder", $.i18n.prop('ip.value.placeholder'));
$(".save").html($.i18n.prop('public.submit'));





$(".save").click(function(){
    var data = {};
    if(window.ipIndex){
        ipList[ipIndex]['value'] = $("input[name='value']").val();
        data = ipList[ipIndex];
    }else {
        data['value']  = $("input[name='value']").val();
        data['type']  = $("[name='type']").val();
    }
    apiAjax("/"+data['type'], data, function(data) {
        if (data.code == 0) {
            alert("保存成功")
        }
    });
});

$(".back").click(function(){
    window.ipIndex = null;
	load_page("ip/list.html",true);
});



</script>